﻿using System;
using System.Collections;
using System.Collections.Generic;

using AUV5.Model;
using AUV5.DAL.Interface;

namespace AUV5.DAL.Dao
{
    /// <summary>
    /// 功能：     OrderInfo业务接口的实现
    /// 作者：     lwl
    /// 日期：     2011/10/14
    /// 修改日期： 
    /// 修改人：
    /// 修改内容：
    /// </summary>
    public class OrderInfoSqlMapDao : BaseSqlMapDao, IOrderInfoDao
    {
        private static OrderInfoSqlMapDao instance = null;
        private static object syncRoot = new object();

        private OrderInfoSqlMapDao()
        {
            //
            // TODO: 此处添加OrderInfoSqlMapDao的构造函数
            //
        }
        public static IOrderInfoDao Instance
        {
            get
            {
                if (instance == null)
                {
                    lock (syncRoot)
                    {
                        if (instance == null)
                        {
                            instance = new OrderInfoSqlMapDao();
                        }
                    }
                }
                return instance;
            }
        }

        /// <summary>
        /// 得到最大行数
        /// </summary>
        /// <returns></returns>
        public int GetMaxCounts()
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectOrderInfoByMaxCounts", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到列表
        /// </summary>
        /// <returns></returns>
        public System.Collections.Generic.IList<OrderInfo> GetList()
        { 
            try
            {
                return ExecuteQueryForList<OrderInfo>("SelectOrderInfo", null);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通过不同参数得到列表
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public System.Collections.Generic.IList<OrderInfo> GetListByParameters(object objParameters)
        {
            try
            {
                return ExecuteQueryForList<OrderInfo>("SelectOrderInfoByParameters", objParameters);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 得到明细
        /// </summary>
        /// <param name="OrderID"></param>
        /// <returns></returns>
        public OrderInfo GetDetail(System.String orderid)
        {
            try
            {
                Handler.OrderInfoHandler handler = new Handler.OrderInfoHandler();
               
                ExecuteWithRowDelegate("SelectOrderInfo", orderid, new IBatisNet.DataMapper.RowDelegate(handler.GetFullList));

                if (handler.orderlist.Count > 0)
                {
                    return handler.orderlist[0];
                }
                else
                {
                    return null;
                }
                //return ExecuteQueryForObject<OrderInfo>("SelectOrderInfo", orderid) as OrderInfo;
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="orderinfo"></param>
        /// <returns></returns>
        public object Add(OrderInfo orderinfo)
        {
            //int id = GetId("OrderInfo");
            //orderinfo.OrderID = id;

            try
            {
                return ExecuteInsert("InsertOrderInfo", orderinfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="orderinfo"></param>
        /// <returns></returns>
        public int Update(OrderInfo orderinfo)
        {
            try
            {
                return ExecuteUpdate("UpdateOrderInfo", orderinfo);
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="OrderID"></param>
        /// <returns></returns>
        public int Delete(System.String orderid)
        {
            try
            {
                return ExecuteDelete("DeleteOrderInfo", orderid);
            }
            catch
            {
                throw;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="orderinfo"></param>
        /// <returns></returns>
        public int Delete(OrderInfo orderinfo)
        {
            try
            {
                return ExecuteDelete("DeleteOrderInfo", orderinfo.OrderID);
            }
            catch
            {
                throw;
            }
        }



        /// <summary>
        /// 得到订单信息集合（分页）
        /// 创建人：Wilson
        /// 创建时间：2011-10-30
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public IList<OrderInfo> GetOrderListPage(object objParameters)
        {
            try
            {
                Handler.OrderInfoHandler handler = new Handler.OrderInfoHandler();
                ExecuteWithRowDelegate("GetOrderInfoPage", objParameters, new IBatisNet.DataMapper.RowDelegate(handler.GetFullList));
                return handler.orderlist;
                //return ExecuteQueryForList<OrderInfo>("GetOrderInfoPage", objParameters);
            }
            catch
            {

                throw;
            }
        }

        /// <summary>
        /// 通过订单号得到订单详情
        /// 创建人：Wilson
        /// 创建时间：2011-11-8
        /// </summary>
        /// <param name="orderCode"></param>
        /// <returns></returns>
        public OrderInfo GetOrderInfoByOrderCode(string orderCode)
        {
            try
            {
                return ExecuteQueryForObject<OrderInfo>("SelectOrderInfoByOrderCode", orderCode) as OrderInfo;
            }
            catch
            {

                throw;
            }
        }

        #region##通过订单号得到订单个数
        /// <summary>
        /// 通过订单号得到订单个数
        /// 创建人：Wilson
        /// 创建时间：2011-11-8
        /// </summary>
        /// <param name="orderCode"></param>
        /// <returns></returns>   
        public int GetOrderInfoCount(string orderCode)
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectOrderInfoCount", orderCode);
            }
            catch
            {
                throw;
            }
        }
        #endregion


        #region##通过订单号更新订单
        /// <summary>
        /// 通过订单号更新订单
        /// 创建人：Wilson
        /// 创建时间：2011-11-8
        /// </summary>
        /// <param name="orderinfo"></param>
        /// <returns></returns>
        public int UpdateOrderInfoByOrderCode(OrderInfo orderinfo)
        {
            try
            {
                return ExecuteUpdate("UpdateOrderInfoByOrderCode", orderinfo);
            }
            catch
            {
                throw;
            }
        }
        #endregion


        #region##通过用户ID得到用户收入
        /// <summary>
        /// 通过用户ID得到用户收入
        /// 创建人：Wilson
        /// 创建时间：2011-11-25
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public decimal GetIncomeByUserId(object objParameters)
        {
            try
            {
                return Convert.ToDecimal(ExecuteQueryForObject("SelectIncomeByParameters", objParameters));
            }
            catch
            {
                throw;
            }
        }
        #endregion



        #region## 通过用户ID得到用户支出
        /// <summary>
        /// 通过用户ID得到用户支出
        /// 创建人：Wilson
        /// 创建时间：2011-11-25
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public decimal GetCostByUserId(object objParameters)
        {
            try
            {
                return Convert.ToDecimal(ExecuteQueryForObject("SelectCostByParameters", objParameters));
            }
            catch
            {
                throw;
            }
        }
        #endregion

        #region##通过用户ID得到用户未付款
        /// <summary>
        /// 通过用户ID得到用户未付款
        /// 创建人：Wilson
        /// 创建时间：2011-11-25
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public decimal GetNotPaymentByUserId(object objParameters)
        {
            try
            {
                return Convert.ToDecimal(ExecuteQueryForObject("SelectNotPaymentByParameters", objParameters));
            }
            catch
            {
                throw;
            }
        }
        #endregion



        #region## 通过条件得到买/卖成功的订单数据
        /// <summary>
        /// 通过条件得到买/卖成功的订单数据
        /// 创建人：Wilson
        /// 创建时间：2011-11-25
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public int GetCompletedByParameters(object objParameters)
        {
            try
            {
                return Convert.ToInt32(ExecuteQueryForObject("SelectCompletedByParameters", objParameters));
            }
            catch
            {
                throw;
            }
        }
        #endregion

        #region##通过条件得到订单数
        /// <summary>
        /// 通过条件得到订单数
        /// 创建人：Wilson
        /// 创建时间：2011-11-27
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public int GetOrderInfoCountByParameters(object objParameters)
        {
            try
            {
                return Convert.ToInt32(ExecuteQueryForObject("SelectOrderInfoCountByParameters", objParameters));
            }
            catch
            {
                throw;
            }
        }
        #endregion

        #region##当前订单之前的订单结束所需要的天数
        /// <summary>
        /// 当前订单之前的订单结束所需要的天数
        /// 创建人：Wilson
        /// 创建时间：2011-12-1
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public int GetEndTimeByParameters(object objParameters)
        {
            try
            {
                return (int)ExecuteQueryForObject("SelectEndTimeByParameters", objParameters);
            }
            catch
            {
                throw;
            }
        }
        #endregion


        /// <summary>
        /// 通过服务ID和订单状态得到订单集合
        /// 创建人：Wilson
        /// 创建时间：2011-12-26
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public IList<OrderInfo> GetOrderInfoByServiceIdAndStatusId(object objParameters)
        {
            try
            {
                return ExecuteQueryForList<OrderInfo>("SelectOrderInfoByCondition", objParameters);
            }
            catch
            {
                throw;
            }

        }

        /// <summary>
        /// 通地买家ID和订单状态得到强制关闭的钱数
        /// 创建人：Wilson
        /// 创建时间：2011-12-27
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public decimal GetForceOrderByParameters(object objParameters)
        {
            try
            {
                return Convert.ToDecimal(ExecuteQueryForObject("SelectForceByParameters", objParameters));
            }
            catch
            {
                throw;
            }
        }

        /// <summary>
        /// 通地条件得到关闭订单应退回的价格
        /// 创建人：Wilson
        /// 创建时间：2011-12-28
        /// </summary>
        /// <param name="objParameters"></param>
        /// <returns></returns>
        public decimal GetClosedPayment(object objParameters)
        {
            try
            {
                return Convert.ToDecimal(ExecuteQueryForObject("SelectClosedPayment", objParameters));
            }
            catch
            {
                throw;
            }
        }
    }
}
